﻿#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

/*
char* MyStrchr(char* arr, char ch)
{
	int i = 0;
	while (arr[i] != '\0')
	{
		if (arr[i] == ch)
		{
			return &arr[i];
		}
		i++;
	}
	return NULL;
}
*/
char* MyStrchr(const char* arr, char ch)
{
	char* p = arr;
	while (*p != '\0')
	{
		if (*p == ch)
		{
			return p;
		}
		p++;
	}
	return NULL;
}

//main79：指针实现strchr函数字符串查找字符
int main79()
{
	char arr[] = "hello world";
	char ch = 'f';//o-->f
	//char* p = strchr(arr, ch);
	char* p = MyStrchr(arr, ch);
	printf("1.输出strchr函数，在字符串arr中查找字符ch的结果：%s\n", p);//o world-->o world-->NULL

	system("pause");
	return EXIT_SUCCESS;
}